package com.gz.logistics.library.listener;

import com.gz.logistics.library.util.Constants;
import com.gz.logistics.library.util.CrashHandler;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 签收某个预出库单下的所有订单监听器
 * author wanner1991
 */
public abstract class SignAllOrdersOfTheAssembleListener extends BaseListener {
    private String TAG = SignAllOrdersOfTheAssembleListener.class.getSimpleName();

    @Override
    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
        try {
            int status = response.getInt(Constants.REQ_STATUS);
            String msg = response.getString(Constants.REQ_MSG);
            switch(status){
                case Constants.REQ_OK:
                    onResponseSuccess();
                    break;
                case Constants.REQ_USEID_IS_EMPTY: // 用户ID为空
                case Constants.REQ_USER_FORBIDDENED: //该用户不属于物流员账号
                    onResponseFailed();
                case Constants.REQ_LOGISTICS_SIGN_FAIL: //未签收起始时间不能为空
                    onThisAssembleIsDiscarder();
                    break;
                case Constants.REQ_PART_ORDERS_SIGN_FAIL: //未签收终止时间不能为空
                    onNoMoreData();
                    break;
                case Constants.REQ_THIS_ORDER_IS_EMPTY://整体确认物流签收全部失败
                    onNoSignableOrderInThisAssemble();
                    break;
                case Constants.REQ_ASSEMBLE_IS_DISCARDED://签收其下所有订单物流签收部分失败
                    onPartOrdersSignFail();
                    break;
                default:
                    onResponseFailed();


            }

        } catch (JSONException e) {
            onFailure(statusCode, headers, e, new JSONObject());
        }
    }
    public abstract void onPartOrdersSignFail();
    public abstract void onNoSignableOrderInThisAssemble();
    public abstract void onThisAssembleIsDiscarder();
    public abstract void onResponseSuccess();

    @Override
    public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
        CrashHandler.e(throwable);
        onResponseFailed();
    }


    @Override
    public void onNoMoreData() {

    }
}
